tup1 = (1, 2, 3)
tup2 = 4, 5, 6
single_tup = (7,)
empty_tup = ()



print(type(tup1))
print(tup2)

try:
    tup1[0] = 10
except TypeError as e:
    print(f"错误{e}")



new_tup = tup1 + (4,)
print(new_tup)


import sys
lst = [1, 2, 3]
tup = (1, 2, 3)

print(sys.getsizeof(lst))
print(sys.getsizeof(tup))


valid_dict = {(1,2): "坐标"}
invalid_dict = {[1,2]: "列表"}




student = {"name": "张三","age": 20, "course": ["Match","CS"]}


print(student["name"])
print(student.get("grade","N/A"))


student["age"] = 21
student["grade"] = "A"
print(student)


del student["courses"]
popped = student.pop("age")
print(f"删除的年龄: {popped}, 剩余: {student}")






dict1 = {"a": 1, "b": 2}
dict2 = {"b": 3, "c": 4}


new_dict = dict1 | dict2
print(new_dict)





for key in student.keys():
    print(key)

for value in student.values():
    print(value)

for key, value in student.items():
    print(f"{key}: {value}")



for key in sorted(student.keys()):
    print(f"[{key} -> {student[key]}")


squared = {x: x**2 for x in range(5)}
print(squared)



def word_frequency(text):
    freq = {}
    for word in text.lower().split():
        freq[word] = freq.get(word, 0) + 1
    return freq


text ="Python is easy Python is powerful"
result = word_frequency(text)



for word, count in sorted(result.items(), key=lambda x: -x[1]):
    print(f"{word}: {count}次")


